
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>CopyOnWriteArrayList和Collections.synchronizedList有什么区别？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>CopyOnWriteArrayList和Collections.synchronizedList有什么区别？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">CopyOnWriteArrayList 是如何实现线程安全的？其核心机制是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CopyOnWriteArrayList 采用“写时复制”(Copy-On-Write)机制。当有写操作（如 add、remove）时，它会创建底层数组的副本，在新副本上进行操作，完成后将新副本替换为原数组。读操作则不需要加锁，直接读取当前数组。</div>
          </div>
          <div class="card-source">来源: 区别 -> 工作机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Collections.synchronizedList 保证线程安全的方式是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它通过同步(synchronization)机制实现线程安全。它将一个普通的List包装起来，所有的读写操作都被加上了同步锁（synchronized），确保在多线程环境下只有一个线程能访问List的方法。</div>
          </div>
          <div class="card-source">来源: 区别 -> 工作机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">性能</div>
          <div class="card-question">为什么说 CopyOnWriteArrayList “读操作性能高，写操作性能较低”？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">性能</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">读操作性能高是因为它不需要加锁，可以在高并发场景下并发执行。写操作性能较低是因为每次写操作都会创建数组副本，这带来了较大的内存开销和时间成本。</div>
          </div>
          <div class="card-source">来源: 区别 -> 性能</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">CopyOnWriteArrayList 和 Collections.synchronizedList 在数据一致性方面有何主要区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CopyOnWriteArrayList 提供的是“弱一致性”，读操作可能看不到最新的写操作结果，因为读的是写操作前的快照。而 Collections.synchronizedList 提供“强一致性”，因为所有操作都加锁，保证每次读操作都能看到最新的写操作结果。</div>
          </div>
          <div class="card-source">来源: 区别 -> 一致性</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在内存消耗方面，CopyOnWriteArrayList 和 Collections.synchronizedList 有什么不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CopyOnWriteArrayList 的内存消耗较大，因为每次写操作都会复制整个底层数组。而 Collections.synchronizedList 没有额外的内存消耗，其内存使用与普通的List相同。</div>
          </div>
          <div class="card-source">来源: 区别 -> 内存消耗</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">根据文档，CopyOnWriteArrayList 和 Collections.synchronizedList 各自最适合的应用场景是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CopyOnWriteArrayList 适合读操作频繁、写操作较少的场景，如缓存、配置信息列表。Collections.synchronizedList 适合读写操作均衡，或者写操作相对较多但整体并发量不高的场景。</div>
          </div>
          <div class="card-source">来源: 适用场景</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
